﻿using System;
using System.ComponentModel;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
using YArchitech.LIB;
using YArchitech.LIB.YJKControls;
using YJKDimensionModel.Properties;

namespace YJKDimensionModel.SymbolTextSetting
{
	public partial class SymbolTextForm : System.Windows.Forms.Form
	{
		private GridCollector GridCollector { get; set; }

		private IndexMarkCollector IndexMarkCollector { get; set; }

		public SymbolTextForm()
		{
			this.InitializeComponent();
		}

		public SymbolTextForm(GridCollector gridCollector, IndexMarkCollector indexMarkCollector)
		{
			this.GridCollector = gridCollector;
			this.IndexMarkCollector = indexMarkCollector;
			this.InitializeComponent();
		}

		private void btnCancel_Click(object sender, EventArgs e)
		{
			base.Close();
		}

		private void btnSure_Click(object sender, EventArgs e)
		{
			if (this.radInCircle.Checked)
			{
				GridFontSetting gridFontSetting = new GridFontSetting(this.GridCollector, GridAndIndexMarkOper.InTheCircle);
				gridFontSetting.DoSetGridAndIndexMarkStyle();
				IndexMarkFontSetting indexMarkFontSetting = new IndexMarkFontSetting(this.IndexMarkCollector, GridAndIndexMarkOper.InTheCircle);
				indexMarkFontSetting.DoSetGridAndIndexMarkStyle();
			}
			else if (this.radOldStyle.Checked)
			{
				GridFontSetting gridFontSetting2 = new GridFontSetting(this.GridCollector, GridAndIndexMarkOper.OldStyle);
				gridFontSetting2.DoSetGridAndIndexMarkStyle();
				IndexMarkFontSetting indexMarkFontSetting2 = new IndexMarkFontSetting(this.IndexMarkCollector, GridAndIndexMarkOper.OldStyle);
				indexMarkFontSetting2.DoSetGridAndIndexMarkStyle();
			}
			else if (this.radOutCircle.Checked)
			{
				GridFontSetting gridFontSetting3 = new GridFontSetting(this.GridCollector, GridAndIndexMarkOper.OutTheCircle);
				gridFontSetting3.DoSetGridAndIndexMarkStyle();
				IndexMarkFontSetting indexMarkFontSetting3 = new IndexMarkFontSetting(this.IndexMarkCollector, GridAndIndexMarkOper.OutTheCircle);
				indexMarkFontSetting3.DoSetGridAndIndexMarkStyle();
			}
			base.Close();
		}

		private void SymbolTextForm_Load(object sender, EventArgs e)
		{
			//base.Icon = Resource.YArchitechIcon;
			this.GetData();
		}

		private void radInCircle_Click(object sender, EventArgs e)
		{
            
            //this.picThumbnails.Image = YJKDimensionModel.Properties.Resources.InCircle;
		}

		private void radOldStyle_Click(object sender, EventArgs e)
		{
            //this.picThumbnails.Image = YJKDimensionModel.Properties.Resources.OldStyle;
		}

		private void radOutCircle_Click(object sender, EventArgs e)
		{
            //this.picThumbnails.Image = YJKDimensionModel.Properties.Resources.OutCircle;
		}

		private void SaveData()
		{
			string environmentVariable = Environment.GetEnvironmentVariable("TEMP");
			DirectoryInfo directoryInfo = new DirectoryInfo(environmentVariable);
			string path = directoryInfo.FullName + "\\SymbolTextFormData.txt";
			FileStream fileStream = new FileStream(path, FileMode.OpenOrCreate);
			StreamWriter streamWriter = new StreamWriter(fileStream);
			streamWriter.Flush();
			streamWriter.WriteLine(this.radInCircle.Checked);
			streamWriter.WriteLine(this.radOutCircle.Checked);
			streamWriter.WriteLine(this.radOldStyle.Checked);
			streamWriter.Close();
			fileStream.Close();
		}

		private bool GetData()
		{
			bool result;
			try
			{
				string path = Ultility.GetUserTempDirectory() + "\\SymbolTextFormData.txt";
				FileStream fileStream = new FileStream(path, FileMode.OpenOrCreate);
				StreamReader streamReader = new StreamReader(fileStream);
				if (streamReader.ReadLine() == "True")
				{
					this.radInCircle.Checked = true;
                    //this.picThumbnails.Image = YJKDimensionModel.Properties.Resources.InCircle;
				}
				else if (streamReader.ReadLine() == "True")
				{
					this.radOutCircle.Checked = true;
                    //this.picThumbnails.Image = YJKDimensionModel.Properties.Resources.OutCircle;
				}
				else
				{
					this.radOldStyle.Checked = true;
                    //this.picThumbnails.Image = YJKDimensionModel.Properties.Resources.OldStyle;
				}
				streamReader.Close();
				fileStream.Close();
				result = true;
			}
			catch (Exception)
			{
				this.radOldStyle.Checked = true;
                //this.picThumbnails.Image = global::YJKDimensionModel.Properties.Resources.OldStyle;
				result = false;
			}
			return result;
		}

		private void SymbolTextForm_KeyPress(object sender, KeyPressEventArgs e)
		{
			if (e.KeyChar == '\u001b')
			{
				base.Close();
			}
		}

		private void SymbolTextForm_FormClosed(object sender, FormClosedEventArgs e)
		{
			this.SaveData();
		}
	}
}
